﻿using UnityEngine;
using System.Collections;

public class FireControlBehaviour : MonoBehaviour {
	//Skott-variabel:
	public Transform primaryProjectile;
	public Transform secondaryProjectile;

	//Knappinställning:
	public string fireButton = "Fire1";
	public string altFireButton = "Fire2";

	//Skjutainställningar:
	public float fireRate = 0.5F;
	public Quaternion fireRotation = Quaternion.AngleAxis(90, Vector3.right);
	
	//State variables:
	private float nextFire = 0.0F;


	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {
		//Skjut om man trycker på skjutaknappen och tillräckligt lång tid gått.
		if (Input.GetButton (fireButton) && Time.time > nextFire) {
			nextFire = Time.time + fireRate;
			fire ();
		}

	}
	
	//Skjut en projektil!

	private void fire() {
		Quaternion angle = Quaternion.AngleAxis (rigidbody2D.transform.rotation.eulerAngles.z+90, Vector3.forward);
		Instantiate (primaryProjectile, rigidbody2D.transform.position, angle);
	}
}
